package com.ossjk.api.controller;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.util.CommonMethod;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.oa.finance.service.ISalaryService;
import com.ossjk.oa.paid.service.IPaidService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 *  邓钧
 * 按月查询个人工资
 */

@RestController
@RequestMapping("/api")
public class PayController extends BaseController {

    @Autowired
    private ISalaryService iSalaryService;

    @Autowired
    private IPaidService iPaidService;


    //按月查看个人工资表
    @ApiOperation(value = "个人工资", notes = "按月查看个人工资表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mth", value = "日期", paramType = "query", dataType = "String")
    })
    @GetMapping("/selectPay")
    public ResponseBean selectPay(String mth){
        //登录就拿到个人id
        String id = getCurrnetUserId();

        if(CommonUtil.isBlank(mth)){

            Calendar now = Calendar.getInstance();
            if (now.get(Calendar.DAY_OF_MONTH) > 20) {
                mth = CommonMethod.calMth(0, now.getTime());//大于20号就是本月
            }else{
                mth = CommonMethod.calMth(-1, now.getTime());//小于20号就是上一个月
            }

        }

        Wrapper wrapper = Condition.create().isWhere(true).like("wagemonth",mth).eq("empid",id);
        return (ResponseBean) responseSuccess(iSalaryService.selectAllSalary(wrapper));

    }
}
